package practicedemo54;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //定义三个用户
        User user1 = new User("001", "Stephen Hu", "123456789");
        User user2 = new User("002", "Hu", "987654321");
        User user3 = new User("003", "Stephen", "0000");
        //创建一个集合
        ArrayList<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);

        method(list);
    }

    public static void method(ArrayList<User> list) {
        System.out.println("输入id");
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        boolean Key = false;
        for (int i = 0; i < list.size(); i++) {
            if (x.equals(list.get(i).getId())) {
                Key = true;
                System.out.println(Key);
                System.out.println(list.get(i).toString());
                break;
            }
        }
        if (!Key) {
            System.out.println(Key);
            System.out.println("没有此id的学生");
        }
    }
}
